package com.speak.sparkadminserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.speak.sparkadminserver.dao.NutUserDao;
import com.speak.sparkadminserver.domain.NutUser;
import com.speak.sparkadminserver.service.NutUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/2/17 22:18
 */
@Service
public class NutUserServiceImpl<M,T> extends ServiceImpl<NutUserDao, NutUser> implements NutUserService{
    @Autowired
    private NutUserDao dao;
    @Override
    public Page getAll(Map<String,Object> map) {
        QueryWrapper wrapper = new QueryWrapper();
        String username =(String) map.get("query");
        Integer pagenum = Integer.parseInt(((String) map.get("pagenum")));
        Integer pagesize = Integer.parseInt(((String) map.get("pagesize")));
        Page page = new Page(pagenum, pagesize);
        if (username!=null){
            wrapper.like("username", username);
        }
        wrapper.notIn("id","1");
        wrapper.notIn("del_flag","1");
        Page page1 = dao.selectMapsPage(page, wrapper);
        return page1;
    }

    @Override
    public NutUser getUser(String username) {
        return dao.getUser(username);
    }

    @Override
    public boolean getUsersNumber(String username) {
        List<NutUser> usersNumber = dao.getUsersNumber(username);
        if (usersNumber.size() > 0) {
            return false;
        }
        return true;
    }

    @Override
    public Long getId(String username) {
        return dao.getId(username);
    }

    @Override
    public NutUser getUserById(Long id) {
        return dao.getUserById(id);
    }
}
